Add TAL-Reverb-II plugin to test
[juce-lv2.git] / juce / source / extras / the jucer / src / model / components / jucer_TextEditorHandler.h
blobfe89c6d55fed0e313d175ed7adadb53c33d6942e
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCER_TEXTEDITORHANDLER_JUCEHEADER__
27 #define __JUCER_TEXTEDITORHANDLER_JUCEHEADER__
30 //==============================================================================
31 /**
33 class TextEditorHandler : public ComponentTypeHandler
35 public:
36 //==============================================================================
37 TextEditorHandler()
38 : ComponentTypeHandler ("Text Editor", "TextEditor", typeid (TextEditor), 150, 24)
40 registerColour (TextEditor::textColourId, "text", "textcol");
41 registerColour (TextEditor::backgroundColourId, "background", "bkgcol");
42 registerColour (TextEditor::highlightColourId, "highlight", "hilitecol");
43 registerColour (TextEditor::outlineColourId, "outline", "outlinecol");
44 registerColour (TextEditor::shadowColourId, "shadow", "shadowcol");
45 registerColour (CaretComponent::caretColourId, "caret", "caretcol");
48 //==============================================================================
49 Component* createNewComponent (JucerDocument*)
51 return new TextEditor ("new text editor");
54 XmlElement* createXmlFor (Component* comp, const ComponentLayout* layout)
56 XmlElement* e = ComponentTypeHandler::createXmlFor (comp, layout);
57 TextEditor* te = (TextEditor*) comp;
59 e->setAttribute ("initialText", comp->getProperties() ["initialText"].toString());
61 e->setAttribute ("multiline", te->isMultiLine());
62 e->setAttribute ("retKeyStartsLine", te->getReturnKeyStartsNewLine());
63 e->setAttribute ("readonly", te->isReadOnly());
64 e->setAttribute ("scrollbars", te->areScrollbarsShown());
65 e->setAttribute ("caret", te->isCaretVisible());
66 e->setAttribute ("popupmenu", te->isPopupMenuEnabled());
68 return e;
71 bool restoreFromXml (const XmlElement& xml, Component* comp, const ComponentLayout* layout)
73 if (! ComponentTypeHandler::restoreFromXml (xml, comp, layout))
74 return false;
76 TextEditor* te = (TextEditor*) comp;
77 TextEditor defaultEditor;
79 te->setMultiLine (xml.getBoolAttribute ("multiline", defaultEditor.isMultiLine()));
80 te->setReturnKeyStartsNewLine (xml.getBoolAttribute ("retKeyStartsLine", defaultEditor.getReturnKeyStartsNewLine()));
81 te->setReadOnly (xml.getBoolAttribute ("readonly", defaultEditor.isReadOnly()));
82 te->setScrollbarsShown (xml.getBoolAttribute ("scrollbars", defaultEditor.areScrollbarsShown()));
83 te->setCaretVisible (xml.getBoolAttribute ("caret", defaultEditor.isCaretVisible()));
84 te->setPopupMenuEnabled (xml.getBoolAttribute ("popupmenu", defaultEditor.isPopupMenuEnabled()));
86 const String initialText (xml.getStringAttribute ("initialText"));
87 te->setText (initialText, false);
88 te->getProperties().set ("initialText", initialText);
89 return true;
92 void getEditableProperties (Component* component, JucerDocument& document, Array <PropertyComponent*>& properties)
94 ComponentTypeHandler::getEditableProperties (component, document, properties);
96 TextEditor* const t = dynamic_cast <TextEditor*> (component);
97 jassert (t != 0);
99 properties.add (new TextEditorInitialTextProperty (t, document));
100 properties.add (new TextEditorMultiLineProperty (t, document));
101 properties.add (new TextEditorReadOnlyProperty (t, document));
102 properties.add (new TextEditorScrollbarsProperty (t, document));
103 properties.add (new TextEditorCaretProperty (t, document));
104 properties.add (new TextEditorPopupMenuProperty (t, document));
106 addColourProperties (t, document, properties);
109 const String getCreationParameters (Component* component)
111 return quotedString (component->getName());
114 void fillInCreationCode (GeneratedCode& code, Component* component, const String& memberVariableName)
116 ComponentTypeHandler::fillInCreationCode (code, component, memberVariableName);
118 TextEditor* const te = dynamic_cast <TextEditor*> (component);
119 jassert (te != 0);
121 String s;
122 s << memberVariableName << "->setMultiLine (" << boolToString (te->isMultiLine()) << ");\n"
123 << memberVariableName << "->setReturnKeyStartsNewLine (" << boolToString (te->getReturnKeyStartsNewLine()) << ");\n"
124 << memberVariableName << "->setReadOnly (" << boolToString (te->isReadOnly()) << ");\n"
125 << memberVariableName << "->setScrollbarsShown (" << boolToString (te->areScrollbarsShown()) << ");\n"
126 << memberVariableName << "->setCaretVisible (" << boolToString (te->isCaretVisible()) << ");\n"
127 << memberVariableName << "->setPopupMenuEnabled (" << boolToString (te->isPopupMenuEnabled()) << ");\n"
128 << getColourIntialisationCode (component, memberVariableName)
129 << memberVariableName << "->setText (" << quotedString (te->getProperties() ["initialText"].toString()) << ");\n\n";
131 code.constructorCode += s;
134 private:
135 //==============================================================================
136 class TextEditorMultiLineProperty : public ComponentChoiceProperty <TextEditor>
138 public:
139 TextEditorMultiLineProperty (TextEditor* component_, JucerDocument& document_)
140 : ComponentChoiceProperty <TextEditor> ("mode", component_, document_)
142 choices.add ("single line");
143 choices.add ("multi-line, return key starts new line");
144 choices.add ("multi-line, return key disabled");
147 //==============================================================================
148 void setIndex (int newIndex)
150 document.perform (new TextEditorMultilineChangeAction (component, *document.getComponentLayout(), newIndex),
151 "Change TextEditor multiline mode");
154 int getIndex() const
156 return component->isMultiLine() ? (component->getReturnKeyStartsNewLine() ? 1 : 2) : 0;
159 private:
160 class TextEditorMultilineChangeAction : public ComponentUndoableAction <TextEditor>
162 public:
163 TextEditorMultilineChangeAction (TextEditor* const comp, ComponentLayout& layout, const int newState_)
164 : ComponentUndoableAction <TextEditor> (comp, layout),
165 newState (newState_)
167 oldState = comp->isMultiLine() ? (comp->getReturnKeyStartsNewLine() ? 1 : 2) : 0;
170 bool perform()
172 showCorrectTab();
173 getComponent()->setMultiLine (newState > 0);
174 getComponent()->setReturnKeyStartsNewLine (newState == 1);
175 changed();
176 return true;
179 bool undo()
181 showCorrectTab();
182 getComponent()->setMultiLine (oldState > 0);
183 getComponent()->setReturnKeyStartsNewLine (oldState == 1);
184 changed();
185 return true;
188 int newState, oldState;
192 //==============================================================================
193 class TextEditorReadOnlyProperty : public ComponentBooleanProperty <TextEditor>
195 public:
196 TextEditorReadOnlyProperty (TextEditor* component_, JucerDocument& document_)
197 : ComponentBooleanProperty <TextEditor> ("editable", "Editable", "Editable", component_, document_)
201 //==============================================================================
202 void setState (bool newState)
204 document.perform (new TextEditorReadonlyChangeAction (component, *document.getComponentLayout(), ! newState),
205 "Change TextEditor read-only mode");
208 bool getState() const { return ! component->isReadOnly(); }
210 private:
211 class TextEditorReadonlyChangeAction : public ComponentUndoableAction <TextEditor>
213 public:
214 TextEditorReadonlyChangeAction (TextEditor* const comp, ComponentLayout& layout, const bool newState_)
215 : ComponentUndoableAction <TextEditor> (comp, layout),
216 newState (newState_)
218 oldState = comp->isReadOnly();
221 bool perform()
223 showCorrectTab();
224 getComponent()->setReadOnly (newState);
225 changed();
226 return true;
229 bool undo()
231 showCorrectTab();
232 getComponent()->setReadOnly (oldState);
233 changed();
234 return true;
237 bool newState, oldState;
241 //==============================================================================
242 class TextEditorScrollbarsProperty : public ComponentBooleanProperty <TextEditor>
244 public:
245 TextEditorScrollbarsProperty (TextEditor* component_, JucerDocument& document_)
246 : ComponentBooleanProperty <TextEditor> ("scrollbars", "Scrollbars enabled", "Scrollbars enabled", component_, document_)
250 //==============================================================================
251 void setState (bool newState)
253 document.perform (new TextEditorScrollbarChangeAction (component, *document.getComponentLayout(), newState),
254 "Change TextEditor scrollbars");
257 bool getState() const { return component->areScrollbarsShown(); }
259 private:
260 class TextEditorScrollbarChangeAction : public ComponentUndoableAction <TextEditor>
262 public:
263 TextEditorScrollbarChangeAction (TextEditor* const comp, ComponentLayout& layout, const bool newState_)
264 : ComponentUndoableAction <TextEditor> (comp, layout),
265 newState (newState_)
267 oldState = comp->areScrollbarsShown();
270 bool perform()
272 showCorrectTab();
273 getComponent()->setScrollbarsShown (newState);
274 changed();
275 return true;
278 bool undo()
280 showCorrectTab();
281 getComponent()->setScrollbarsShown (oldState);
282 changed();
283 return true;
286 bool newState, oldState;
290 //==============================================================================
291 class TextEditorCaretProperty : public ComponentBooleanProperty <TextEditor>
293 public:
294 TextEditorCaretProperty (TextEditor* component_, JucerDocument& document_)
295 : ComponentBooleanProperty <TextEditor> ("caret", "Caret visible", "Caret visible", component_, document_)
299 //==============================================================================
300 void setState (bool newState)
302 document.perform (new TextEditorCaretChangeAction (component, *document.getComponentLayout(), newState),
303 "Change TextEditor caret");
306 bool getState() const { return component->isCaretVisible(); }
308 private:
309 class TextEditorCaretChangeAction : public ComponentUndoableAction <TextEditor>
311 public:
312 TextEditorCaretChangeAction (TextEditor* const comp, ComponentLayout& layout, const bool newState_)
313 : ComponentUndoableAction <TextEditor> (comp, layout),
314 newState (newState_)
316 oldState = comp->isCaretVisible();
319 bool perform()
321 showCorrectTab();
322 getComponent()->setCaretVisible (newState);
323 changed();
324 return true;
327 bool undo()
329 showCorrectTab();
330 getComponent()->setCaretVisible (oldState);
331 changed();
332 return true;
335 bool newState, oldState;
339 //==============================================================================
340 class TextEditorPopupMenuProperty : public ComponentBooleanProperty <TextEditor>
342 public:
343 TextEditorPopupMenuProperty (TextEditor* component_, JucerDocument& document_)
344 : ComponentBooleanProperty <TextEditor> ("popup menu", "Popup menu enabled", "Popup menu enabled", component_, document_)
348 //==============================================================================
349 void setState (bool newState)
351 document.perform (new TextEditorPopupMenuChangeAction (component, *document.getComponentLayout(), newState),
352 "Change TextEditor popup menu");
355 bool getState() const { return component->isPopupMenuEnabled(); }
357 private:
358 class TextEditorPopupMenuChangeAction : public ComponentUndoableAction <TextEditor>
360 public:
361 TextEditorPopupMenuChangeAction (TextEditor* const comp, ComponentLayout& layout, const bool newState_)
362 : ComponentUndoableAction <TextEditor> (comp, layout),
363 newState (newState_)
365 oldState = comp->isPopupMenuEnabled();
368 bool perform()
370 showCorrectTab();
371 getComponent()->setPopupMenuEnabled (newState);
372 changed();
373 return true;
376 bool undo()
378 showCorrectTab();
379 getComponent()->setPopupMenuEnabled (oldState);
380 changed();
381 return true;
384 bool newState, oldState;
388 //==============================================================================
389 class TextEditorInitialTextProperty : public ComponentTextProperty <TextEditor>
391 public:
392 TextEditorInitialTextProperty (TextEditor* component_, JucerDocument& document_)
393 : ComponentTextProperty <TextEditor> ("initial text", 10000, true, component_, document_)
396 //==============================================================================
397 void setText (const String& newText)
399 document.perform (new TextEditorInitialTextChangeAction (component, *document.getComponentLayout(), newText),
400 "Change TextEditor initial text");
403 const String getText() const
405 return component->getProperties() ["initialText"];
408 private:
409 class TextEditorInitialTextChangeAction : public ComponentUndoableAction <TextEditor>
411 public:
412 TextEditorInitialTextChangeAction (TextEditor* const comp, ComponentLayout& layout, const String& newState_)
413 : ComponentUndoableAction <TextEditor> (comp, layout),
414 newState (newState_)
416 oldState = comp->getProperties() ["initialText"];
419 bool perform()
421 showCorrectTab();
422 getComponent()->setText (newState, false);
423 getComponent()->getProperties().set ("initialText", newState);
424 changed();
425 return true;
428 bool undo()
430 showCorrectTab();
431 getComponent()->setText (oldState, false);
432 getComponent()->getProperties().set ("initialText", oldState);
433 changed();
434 return true;
437 String newState, oldState;
443 #endif // __JUCER_TEXTEDITORHANDLER_JUCEHEADER__